package com.pfs.internal.timestamp.repositories;

import java.util.List;

import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.ParameterExpression;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import com.pfs.internal.timestamp.entities.HWIndependentDevices;

public class HWIndependentDevicesRepositoryImpl extends BaseRepository<HWIndependentDevices, Integer> implements HWIndependentDevicesRepository {
	public List<HWIndependentDevices> findAllIn() {

		CriteriaBuilder cb = entityManager.getCriteriaBuilder();
		CriteriaQuery<HWIndependentDevices> myquery = cb.createQuery(HWIndependentDevices.class);
		Root<HWIndependentDevices> root = myquery.from(HWIndependentDevices.class);

		ParameterExpression<Integer> deletedParamExp = cb.parameter(Integer.class, "deleted");
		// ParameterExpression<Integer> hwDevIdParamExp =
		// cb.parameter(Integer.class, "hWDeviceID");
		ParameterExpression<Integer> devTypeParamExp = cb.parameter(Integer.class, "deviceType");
		ParameterExpression<Integer> devSubType1ParamExp = cb.parameter(Integer.class, "deviceSubType1");
		ParameterExpression<Integer> hwDevSubId1ParamExp = cb.parameter(Integer.class, "hWDeviceSubID1");
		ParameterExpression<String> nameParamExp = cb.parameter(String.class, "name");
		//ParameterExpression<Integer> recordIDParamExp = cb.parameter(Integer.class, "recordID");

		Predicate deletedPredicate = cb.equal(root.<Integer> get("deleted"), deletedParamExp);
		// Predicate hwDevIdPredicate = cb.in(hwDevIdParamExp);
		Predicate devTypeParamPredicate = cb.equal(root.<Integer> get("deviceType"), devTypeParamExp);
		Predicate devSubType1Predicate = cb.equal(root.<Integer> get("deviceSubType1"), devSubType1ParamExp);
		Predicate hwDevSubId1Predicate = cb.equal(root.<Integer> get("hWDeviceSubID1"), hwDevSubId1ParamExp);
		Predicate namePredicate = cb.notLike(root.<String> get("name"), nameParamExp);
		//Predicate recordID =cb.not(root.<Integer>get("recordID").in(recordIDParamExp));
		
		myquery.select(root).where(cb.and(deletedPredicate, devTypeParamPredicate, devSubType1Predicate, hwDevSubId1Predicate, namePredicate));
		TypedQuery<HWIndependentDevices> someHWDevices = entityManager.createQuery(myquery);

		someHWDevices.setParameter("deleted", 0);
		// someHWDevices.setParameter("hWDeviceID", new Integer[] {6, 8});
		someHWDevices.setParameter("deviceType", 50);
		someHWDevices.setParameter("deviceSubType1", 53);
		someHWDevices.setParameter("hWDeviceSubID1", 3);
		someHWDevices.setParameter("name", "%Server%");
		//someHWDevices.setParameter("recordID", new Integer[] {36,87,89});// server
		return someHWDevices.getResultList();
	}
}
